package com.wicket.okrapp.web.contorller;

import com.github.pagehelper.Page;
import com.wicket.okrapp.biz.service.CycleConfService;
import com.wicket.okrapp.biz.service.dto.req.*;
import com.wicket.okrapp.biz.service.dto.res.*;
import com.wicket.okrapp.common.ro.OkrResult;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@RestController
@RequestMapping("/app/cycleConf/")
public class CycleConfController {

    @Autowired
    CycleConfService cycleConfService;

    /**
   * D3-2查周期配置详情
   */
    @PostMapping("queryCycleConfDetail")
    public OkrResult<QueryCycleConfDetailRespDto> queryCycleConfDetail(@RequestBody @Validated QueryCycleConfDetailReqDto reqDTO){
    return OkrResult.success(cycleConfService.queryCycleConfDetail(reqDTO));
    }

    /**
   * D3-2查周期配置列表
   */
    @PostMapping("queryCycleConfList")
    public OkrResult<QueryCycleConfListRespDto> queryCycleConfList(@RequestBody @Validated QueryCycleConfListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryCycleConfListRespDto retData = cycleConfService.queryCycleConfList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D3-2修改周期配置
   */
    @PostMapping("updateCycleConf")
    public OkrResult<UpdateCycleConfRespDto> updateCycleConf(@RequestBody @Validated UpdateCycleConfReqDto reqDTO){
    return OkrResult.success(cycleConfService.updateCycleConf(reqDTO));
    }

    /**
   * D3-2新增周期配置
   */
    @PostMapping("addCycleConf")
    public OkrResult<AddCycleConfRespDto> addCycleConf(@RequestBody @Validated AddCycleConfReqDto reqDTO){
    return OkrResult.success(cycleConfService.addCycleConf(reqDTO));
    }

    /**
   * D3-4查时段规则详情
   */
    @PostMapping("queryCycleTimeRuleDetail")
    public OkrResult<QueryCycleTimeRuleDetailRespDto> queryCycleTimeRuleDetail(@RequestBody @Validated QueryCycleTimeRuleDetailReqDto reqDTO){
    return OkrResult.success(cycleConfService.queryCycleTimeRuleDetail(reqDTO));
    }

    /**
   * D3-4查时段规则列表
   */
    @PostMapping("queryCycleTimeRuleList")
    public OkrResult<QueryCycleTimeRuleListRespDto> queryCycleTimeRuleList(@RequestBody @Validated QueryCycleTimeRuleListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryCycleTimeRuleListRespDto retData = cycleConfService.queryCycleTimeRuleList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D3-4修改时段规则
   */
    @PostMapping("updateCycleTimeRule")
    public OkrResult<UpdateCycleTimeRuleRespDto> updateCycleTimeRule(@RequestBody @Validated UpdateCycleTimeRuleReqDto reqDTO){
    return OkrResult.success(cycleConfService.updateCycleTimeRule(reqDTO));
    }

    /**
   * D3-4新增时段规则
   */
    @PostMapping("addCycleTimeRule")
    public OkrResult<AddCycleTimeRuleRespDto> addCycleTimeRule(@RequestBody @Validated AddCycleTimeRuleReqDto reqDTO){
    return OkrResult.success(cycleConfService.addCycleTimeRule(reqDTO));
    }
/**
   * D3-2获取时段规则时间信息(公共)
   */
    @PostMapping("obtainCycleTimeRuleInfoCom")
    public OkrResult<ObtainCycleTimeRuleInfoComRespDto> obtainCycleTimeRuleInfoCom(@RequestBody @Validated ObtainCycleTimeRuleInfoComReqDto reqDTO){
    return OkrResult.success(cycleConfService.obtainCycleTimeRuleInfoCom(reqDTO));
    }
}
